/**
 * 
 */
package cn.bblocks.cacheTest.configuration;



import java.net.InetAddress;
import java.net.UnknownHostException;

import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import cn.bblocks.cacheTest.suport.IPUtil;
/** 
* @version:v1.0
* @Description: 获取启动端口号
* @author: jzhao
* @date: 2019年8月13日上午8:33:32
*/
@Component
public class PortListener implements ApplicationListener<ServletWebServerInitializedEvent> {
	
	public static int LOCAL_PORT = -1;
	public static String LOCAL_IP = null;
	
    @Override
    public void onApplicationEvent(ServletWebServerInitializedEvent servletWebServerInitializedEvent) {
    	LOCAL_PORT = servletWebServerInitializedEvent.getWebServer().getPort();
        ///System.out.println(port);
    	LOCAL_IP = IPUtil.getLocalIP();
    }
	
	
    public String getSerInfo() {
    	return LOCAL_IP+"("+LOCAL_PORT+")";
    }
    
    public String getSerIP() {
    	return LOCAL_IP;
    }
}